<?php
include "includeFiles.php";
//if(empty($_SESSION['user_id'])) echo "<script>location.href='login.php';<//script>";

 function unsetArray($array,$delarr){
		foreach ($array as $bkey=>$bvalue){
			foreach ($delarr as $key=>$value){
				if($value == $bkey){
				unset($array[$bkey]);		
			    }
		     }
	    }
		return $array;
	}


function insert($arr,$table){
    	if($arr){
    		foreach ($arr as $key=>$value){
    			@$fild[]  = "`".$key."`";
    			@$vals[]  = "'".$value."'";
    		}
    	}
    	$fild = implode($fild,",");
    	$vals = implode($vals,",");
    	return @$sql  =" insert into ".$table."(".$fild.")values(".$vals.")";
    }
	
	
	function update($arr,$table,$where){
		$str="UPDATE `$table` SET ";
		foreach ($arr as $key=>$value){
			$str_key.="`".$key."`='".$value."',";
		}
		$str_key=substr($str_key,0,-1);
		foreach ($where as $key=>$value){
			$sql_where.="`$key`"."='".$value."' AND";
		}
		$sql_where=substr($sql_where,0,-4);
		return $sql_update=$str.$str_key." WHERE ".$sql_where.";";
		
	}
	
if($_POST['action'] == 'addactivity'){
	$table = "hy_b_3g";
	$post  = unsetArray($_POST,$arr=array('action'));
	$sql   = insert($post,$table);
	$msg   = $objDb->query($sql);
	if($msg){
		echo "<script>alert('添加成功！');location.href='3g_add.php';</script>";
	}else{
		echo "<script>alert('添加失败！');location.href='3g_add.php';</script>";
	}	
} 

if($_POST['action'] == 'updateactivity'){
	$table = "hy_b_3g";
	$post  = unsetArray($_POST,$arr=array('action','id'));
	$where = array("SpecialCateID"=>$_GET['id']);
	$sql   = update($post,$table,$where);
	$msg   = $objDb->query($sql);
	if($msg){
		echo "<script>alert('更新成功！');location.href='3g_add.php?id=".$_GET['id']."';</script>";
	}else{
		echo "<script>alert('更新失败！');location.hre='3g_add.php?id=".$_GET['id']."';</script>";
	}	

}





?>

    <script type="text/javascript" src="../../js/jquery-1.4.4.min.js"></script>
            <link href="../css/style.css" rel="stylesheet" type="text/css" />
<link href="../css/edit.css" rel="stylesheet" type="text/css" />
<table summary="" id="pagehead" cellpadding="0" cellspacing="0" border="0" width="100%">
  <tr>
    <td width="23%"><h1>3g号码管理</h1></td>
    <td width="77%" class="actions"><table summary="" cellpadding="0" cellspacing="0" border="0" align="right">
      <tr>
        <td class="active"><a href="3g_admin_list.php" class="view">管理列表</a></td>
        <td ><a href="3g_add.php" class="edit">新增</a></td>
      </tr>
    </table></td>
  </tr>
</table>
              
              
         <form action="" method="post">
         
         <? if($_GET['id']){?>
             <input name="action" type="hidden" value="updateactivity" />
             <input name="SpecialCateID" type="hidden" value="<?=$_GET['id']?>" />
             
             <?  
			  $SQL2=" select * from hy_b_3g where SpecialCateID = $id ";
		      $objDb->query($SQL2);
		      $msg = $objDb->get_data();
			 ?>
             
             <? } else {?>
              <input name="action" type="hidden" value="addactivity" />
             <? }?>
                <table cellspacing="0" cellpadding="0" width="100%"  class="maintable" id="feedbackTable">

            <?
                $SQL3="  select COLUMN_NAME,column_comment from INFORMATION_SCHEMA.Columns where table_name='hy_b_3g' ";
				$objDb->query($SQL3);
		        $result = $objDb->get_data();
			    if($result){
					foreach($result as $key=>$value){
						 if($key == 0 ) continue;
				?>  <tr><td>
                
                <label> <?php echo $value['column_comment'];?></label></td>
                <td>
                   <input name="<?=$value['COLUMN_NAME']?>" id="<?=$value['COLUMN_NAME']?>"  type="text" value="<?=$msg[0][$value['COLUMN_NAME']]?>" />
                   </td> </tr>
            <? }} ?>
            <tr><td colspan="2">
            <center>
            <input type="submit" />
            </center>
              </td></tr>
               </table>
            </form>
            
           